package com.dzx.applet;

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @author dzx
 * @ClassName:
 * @Description:
 * @date 2019年07月30日 09:24:39
 */
public class HelloWorld extends Applet implements MouseListener {

    String s = "";
    Image image;
    AudioClip sound;
    int x = 25;
    int y = 25;

    public void paint(Graphics g) {
        g.drawString("Hello World!", 25, 25);
        g.drawString(s, 50, 50);
        g.drawImage(image, 25, 25, this);//this指当前applet作为监视器，一般用this。(25,25)是坐标
        sound.play();
//        sound.loop(); sound.stop();
    }

    @Override
    public void init() {
        String date1 = getParameter("date1");
        image = getImage(getCodeBase(), s);
        AudioClip sound = getAudioClip(getCodeBase(), "声音");
        addMouseListener(this);
    }


    @Override
    public void mouseClicked(MouseEvent e) {
        x = e.getX();
        y = e.getY();
        repaint(); //会调用update()来重绘刷新图形
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
